package com.example.myapp;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_main);

        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });

        Button btn = findViewById(R.id.but);
        btn.setOnClickListener(v -> navigateTo(AboutActivity.class));

        Button textBut = findViewById(R.id.textViewBut);
        textBut.setOnClickListener(v -> navigateTo(view_text.class));

        Button linearLayoutBut = findViewById(R.id.linearLayoutBut);
        linearLayoutBut.setOnClickListener(v -> navigateTo(LinearLayout.class));

        Button relativeBut = findViewById(R.id.relativeBut);
        relativeBut.setOnClickListener(v -> navigateTo(relative_layout.class));

        Button gridBut = findViewById(R.id.gridBut);
        gridBut.setOnClickListener(v -> navigateTo(grid_layout.class));

        Button scrollBut = findViewById(R.id.scrollBut);
        scrollBut.setOnClickListener(v -> navigateTo(scroll_view.class));

        Button zhouqiBut = findViewById(R.id.zhouqiBut);
        zhouqiBut.setOnClickListener(v -> {
            Intent intent = new Intent(this, zhouqi.class);
            intent.putExtra("name", "示例文本");
            intent.putExtra("id", 123);
            startActivity(intent);
        });
    }

//    返回数据
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        Log.d("test", String.format("requestCode: %d resultCode: %d", requestCode, resultCode));

        if (resultCode == 200) {
            String result = data.getStringExtra("result_key");
            Log.d("test", String.format("result: %s", result));
        }
    }

    private void navigateTo(Class<?> cls) {

        Intent intent = new Intent(MainActivity.this, cls);

        startActivity(intent);
    }

}